//异步判断数据库是否含有当前用户
function findUer() {
    //将文本框输入的值发送值服务器
    var tempObject=$("form input:text").eq(0);
    $.ajax({
        url: "/findUser",
        dataType:"json",
        data: {"name":tempObject.val()},
        type:"GET",
        //data封装了服务器放回的数据
        //status：状态
        success: function (data) {
            if(data.msg=='ok'){
                tempObject.css({"border-color":"green","color":"green"});
                tempObject.prop("sure","ok");
            }else{
                tempObject.css({"border-color":"red","color":"red"});
                tempObject.prop("sure","false");
            }
        }
    });
}


//异步判断两次输入的密码是否合法，后期再加上
function verPassword() {
    //取两个密码框
    var password=$("form input:text").eq(1);
    var surePassword=$("form input:text").eq(2);
    if(password.val()!=surePassword.val()){
        password.css({"border-color":"red","color":"red"});
        surePassword.css({"border-color":"red","color":"red"});
        surePassword.prop("sure","false");
    }else{
        password.css({"border-color":"green","color":"green"});
        surePassword.css({"border-color":"green","color":"green"});
        surePassword.prop("sure","ok");
    }
}

//注册流程
//  1.1如果验证通过发送请求到Controller层
//  1.2如果验证没有通过友好在页面提示
function register() {
    var tempObject=$("form input:text").eq(0);
    var surePassword=$("form input:text").eq(2);
    console.log("tempObject:"+tempObject.prop("sure"));
    console.log("password:"+surePassword.prop("sure"));
    if(surePassword.val()!=""&&tempObject.val!=""&&tempObject.prop("sure")=="ok"&&surePassword.prop("sure")=="ok"){
        $.ajax({
            url: "/register",
            dataType:"json",
            data: {"name":tempObject.val(),"password":password.val()},
            type:"GET",
            //data封装了服务器放回的数据
            //status：状态
            success: function (data) {
                console.log(data);
            }
        });
        return true;
    }else{
        alert("请输入正确信息");
        return false;
    };

}